#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    long long countBadPairs(vector<int>& nums) {
        using LL = long long;
        LL n = nums.size();
        LL res = (n - 1) * n / 2;
        unordered_map<int, int> hash;
        for (int i = 0; i < n; i++)
        {
            res -= hash[i - nums[i]]++;
        }
        return res;
    }
};